<template>
  <div class="register">
    <div class="regbox">
      <div class="reg-title">
        <h2>变更商标申请人/注册人名义/地址/变更集体商标/证明商标管理规则/集体成员名单申请</h2>
      </div>
      <div class="reg-form">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="200px"
          class="demo-ruleForm"
        >
          <el-form-item label="申请人名义（中文）：" prop="addr_receiver">
            <el-input v-model="ruleForm.addr_receiver" disabled></el-input>
          </el-form-item>
          <el-form-item label="商标申请号/注册号：" prop="mark_code">
            <el-input v-model="ruleForm.mark_code" placeholder="商标申请号/注册号"></el-input>
          </el-form-item>
          <el-form-item label="是否共有商标：">
            <el-radio-group v-model="ruleForm.status_mark">
              <el-radio label="1">是</el-radio>
              <el-radio label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="变更前名义（中文）：">
            <el-input v-model="ruleForm.name__ch" placeholder="变更前名义（中文）"></el-input>
          </el-form-item>
          <el-form-item label="变更前名义（英文）：">
            <el-input v-model="ruleForm.name__en" placeholder="变更前名义（英文）"></el-input>
          </el-form-item>
          <el-form-item label="变更前地址（中文）：">
            <el-input v-model="ruleForm.addr_ch" placeholder="变更前地址（中文）"></el-input>
          </el-form-item>
          <el-form-item label="变更前地址（英文）：">
            <el-input v-model="ruleForm.addr_en" placeholder="变更前地址（英文）"></el-input>
          </el-form-item>
          <el-form-item label="变更管理规则：">
            <el-checkbox v-model="ruleForm.rule_status">是</el-checkbox>
          </el-form-item>
          <el-form-item label="变更集体成员名单：">
            <el-checkbox v-model="ruleForm.members_status">是</el-checkbox>
          </el-form-item>
          <el-form-item label="变更证明" required>
            <el-button type="success" @click="explain = true">选择图片</el-button>
            <div class="img-box">
              <el-image
                v-for="(item,index) in explainimg"
                :key="index"
                style="width: 100px; height: 100px;margin: 3px; "
                :src="item.url"
                fit="cover"
                :preview-src-list="RxplainPreList"
              ></el-image>
            </div>
          </el-form-item>
          <base-upload @getFile="getFile"></base-upload>
        </el-form>
      </div>
      <div class="r-f-sutbox">
        <button class="r-f-sut" @click="subForm">提交</button>
      </div>
    </div>
    <!-- 选择图片 -->
    <!-- 说明文件 -->
    <el-dialog title="提示" :visible.sync="explain" center>
      <span>需要注意的是内容是默认不居中的</span>
      <el-upload
        action="#"
        list-type="picture-card"
        :auto-upload="false"
        :file-list="explainimg"
        :on-change="changeRxplain"
        :limit="10"
        :on-exceed="exceesLimitRxplain"
        multiple
        drap
      >
        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        <i slot="default" class="el-icon-plus"></i>
        <div slot="file" slot-scope="{file}">
          <img class="el-upload-list__item-thumbnail" :src="file.url" alt />
          <span class="el-upload-list__item-actions">
            <span class="el-upload-list__item-delete" @click="removeRxplain(file)">
              <i class="el-icon-delete"></i>
            </span>
          </span>
        </div>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button @click="explain = false">取 消</el-button>
        <el-button type="primary" @click="explain = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import BaseUpload from "@/components/base-component/BaseUpload";
export default {
  name: "register",
  components: {
    BaseUpload
  },
  data() {
    return {
      ruleForm: {
        change_cert: [],
        addr_ch: "",
        addr_en: "",
        mark_code: "",
        members_status: "",
        name__ch: "",
        name__en: "",
        rule_status: "",
        status_mark: "0",
        confirmImgs: [],
        docImgs: []
      },
      rules: {
        addr_receiver: [
          { required: true, message: "字段不能为空", trigger: "blur" }
        ],
        mark_code: [
          { required: true, message: "字段不能为空", trigger: "blur" }
        ]
      },
      // 删除图片按钮
      disabled: false,
      // 说明文件对话框
      explain: false,
      // 说明文件图片
      explainimg: [],
      formData: new FormData()
    };
  },
  methods: {
    // 获取数据
    getFile(data, data2) {
      console.log(data);
      console.log(data2);
      this.ruleForm.confirmImgs = data2;
      this.ruleForm.docImgs = data;
    },
    subForm() {
      this.ruleForm.change_cert.forEach(item => {
        this.formData.append("change_cert", item.raw);
      });
      var config = {
        header: {
          "Content-Type": "multipart/form-data"
        }
      };
      for (var i = 0; i < this.ruleForm.confirmImgs.length; i++) {
        this.formData.append("confirmImgs", this.ruleForm.confirmImgs[i]);
      }
      for (var a = 0; a < this.ruleForm.docImgs.length; a++) {
        this.formData.append("docImgs", this.ruleForm.docImgs[a]);
      }
      this.formData.append("addr_ch", this.ruleForm.addr_ch);
      this.formData.append("addr_en", this.ruleForm.addr_en);
      this.formData.append("mark_code", this.ruleForm.mark_code);
      this.formData.append("members_status", this.ruleForm.members_status);
      this.formData.append("name__ch", this.ruleForm.name__ch);
      this.formData.append("name__en", this.ruleForm.name__en);
      this.formData.append("rule_status", this.ruleForm.rule_status);
      this.formData.append("status_mark", this.ruleForm.status_mark);
      this.$http
        .post(
          "http://192.168.0.102:8080/proTChAgent/update",
          this.formData,
          config
        )
        .then(function(response) {
          console.log(response);
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    // 文件说明
    changeRxplain(file, fileList) {
      // console.log(fileList)
      this.explainimg.push({ name: file.name, url: file.url, id: file.uid });
      this.ruleForm.change_cert = fileList;
    },
    // 文件说明删除
    removeRxplain(file) {
      const index = this.explainimg.findIndex(el => el.uid === file.uid);
      index !== -1 && this.explainimg.splice(index, 1);
    },
    // 文件说明图片数量超出限制
    exceesLimitRxplain() {
      alert("图片数量超出限制");
    }
  },
  computed: {
    // 文件说明预览数组
    RxplainPreList() {
      return this.explainimg.map(el => {
        return el.url;
      });
    },
  }
};
</script>

<style scoped lang="less">
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active, 2.1.8 版本以下 */ {
  opacity: 0;
}
i,
em {
  font-style: normal;
}
.register {
  width: 100%;
  background-color: #e7e8eb;
  .regbox {
    width: 1240px;
    margin: 0 auto;
    background-color: #fff;
    padding: 20px;
    .reg-title {
      padding: 15px 20px;
      text-align: center;
      border-bottom: 1px solid #e7e8eb;
      h2 {
        font-size: 22px;
        font-weight: 300;
      }
    }
    .reg-form {
      width: 700px;
      margin-left: 120px;
      .el-form-item {
        margin-top: 50px;
      }
    }
    .r-f-sutbox {
      margin-top: 50px;
      text-align: center;
      .r-f-sut {
        padding: 12px 20px;
        color: #fff;
        border: none;
        outline: none;
        border-radius: 5px;
        cursor: pointer;
        background-color: #67c23a;
      }
    }
  }
}
</style>
